package com.yunmai.cloud.web.exception;

import com.yunmai.core.model.error.ErrorMessage;
import org.springframework.http.HttpStatus;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


public class BusinessResponseException extends RuntimeException {

    private HttpStatus httpStatus;

    private List<ErrorMessage> errorMessage;

    public BusinessResponseException(List<ErrorMessage> errorMessage, HttpStatus httpStatus) {
        super(errorMessage.stream()
                .map(ErrorMessage::getMessage)
                .collect(Collectors.joining(",")));
        this.errorMessage = errorMessage;
        this.httpStatus = httpStatus;
    }

    public BusinessResponseException(ErrorMessage errorMessage, HttpStatus httpStatus) {
        super(errorMessage.getMessage());
        this.errorMessage = Collections.singletonList(errorMessage);
        this.httpStatus = httpStatus;
    }

    public BusinessResponseException(ErrorMessage errorMessage) {
        super(errorMessage.getMessage());
        this.errorMessage = Collections.singletonList(errorMessage);;
        this.httpStatus = HttpStatus.BAD_REQUEST;
    }
//
//    public BusinessResponseException(ErrorMessageResponse errorMessageResponse) {
//        super(errorMessageResponse.getMessage());
//        this.errorMessage = Collections.singletonList(ErrorMessage.of(errorMessageResponse.getCode(), errorMessageResponse.getMessage()));
//        this.httpStatus = HttpStatus.BAD_REQUEST;
//    }

    public BusinessResponseException(List<ErrorMessage> errorMessage) {
        super(errorMessage.stream()
                .map(ErrorMessage::getMessage)
                .collect(Collectors.joining(",")));
        this.errorMessage = errorMessage;
        this.httpStatus = HttpStatus.BAD_REQUEST;
    }

//    public BusinessResponseException(ErrorMessageResponse errorMessageResponse,HttpStatus httpStatus) {
//        super(errorMessageResponse.getMessage());
//        this.errorMessage = Collections.singletonList(ErrorMessage.of(errorMessageResponse.getCode(), errorMessageResponse.getMessage()));
//        this.httpStatus = httpStatus;
//    }
    public List<ErrorMessage> getErrorMessage() {
        return errorMessage;
    }


    public HttpStatus getHttpStatus() {
        return httpStatus;
    }


}



